<template>
	<view class="container">
		<TopBtn :title="'我的资料'"></TopBtn>
		<view class="info">
			<view class="currency_card">
				<view class="currency_title flex-sp-center">
					头像
					<view class="txBox" @click="image()">
						<image :src="data.avatar" mode=""></image>
						<uni-icons type="right" size="20" color="#999999"></uni-icons>
					</view>
				</view>
			</view>
			<view class="currency_card mt_30 ">
				<view class="currency_title flex-sp-center mb_30">
					基础信息
					<view class="updata" @click="goinfo('pages/my/EditingInformation/EditingInformation')">
						<image src="@/static/my/updata.png" mode=""></image> 编辑
					</view>
				</view>
				<view class="name_info">
					<view>
						<text>姓名</text> {{data.name}}
					</view>
					<view>
						<text>身份证号</text> {{data.idCardDesensitize}}
					</view>
					<view v-if="data.hospitalName">
						<text>就职医院</text> {{data.hospitalName}}
					</view>
					<view>
						<text>所属科室</text> {{data.departName}}
					</view>
					<view>
						<text>职称</text> {{data.titleName}}
					</view>
					<view v-if="data.diseasesName">
						<text>擅长疾病</text> {{data.diseasesName}}
					</view>
				</view>
			</view>
			<view class="currency_card mt_30 pb_37">
				<view class="currency_title flex-sp-center mb_30">
					擅长
					<view class="updata" @click="goinfo('pages/my/briefIntroduction/briefIntroduction')">
						<image src="@/static/my/updata.png" mode=""></image> 编辑
					</view>
				</view>
				<view class="textareaBox">
					{{data.proficient||"暂无内容"}}
				</view>
			</view>
			<view class="currency_card mt_30 pb_37">
				<view class="currency_title flex-sp-center mb_30">
					医生简介
					<view class="updata" @click="goinfo('pages/my/briefIntroduction/briefIntroduction')">
						<image src="@/static/my/updata.png" mode=""></image> 编辑
					</view>
				</view>
				<view class="textareaBox">
					{{data.introduction||"暂无内容"}}
				</view>
			</view>
			<view class="currency_card mt_30 pb_37">
				<view class="currency_title flex-sp-center mb_30">
					执业证件
					<view class="updata" @click="goinfo('pages/my/EditingInformation/EditingInformation')">
						<image src="@/static/my/updata.png" mode=""></image> 编辑
					</view>
				</view>
				<view class="imgBox" v-if="data.workPermit&&JSON.parse(data.workPermit).length>0">
					<view class="imgTitle mb_30">
						<text></text> 工作证 <image src="@/static/my/xz.png" mode=""></image>
					</view>
					<view class="imgList" v-if="data.workPermit">
						<image :src="n.url" v-for="n in JSON.parse(data.workPermit)" mode="aspectFill"></image>
					</view>
					<view class="explain">
						照片仅用作认证，平台会保护您的隐私，不会泄露给第三方
					</view>
				</view>
				<view class="imgBox mt_30" v-if="data.practiceCertificate&&JSON.parse(data.practiceCertificate).length>0">
					<view class="imgTitle mb_30">
						<text></text> 执业证 <image src="@/static/my/xz.png" mode=""></image>
					</view>
					<view class="imgList" v-if="data.practiceCertificate">
						<image :src="n.url" v-for="n in JSON.parse(data.practiceCertificate)" mode="aspectFill"></image>
					</view>
					<view class="explain">
						照片仅用作认证，平台会保护您的隐私，不会泄露给第三方
					</view>
				</view>
				<view class="imgBox mt_30"
					v-if="data.qualificationCertificate&&JSON.parse(data.qualificationCertificate).length>0">
					<view class="imgTitle mb_30">
						<text></text> 资格证 <image src="@/static/my/xz.png" mode=""></image>
					</view>
					<view class="imgList" v-if="data.qualificationCertificate">
						<image :src="n.url" v-for="n in JSON.parse(data.qualificationCertificate)" mode="aspectFill"></image>
					</view>
					<view class="explain">
						照片仅用作认证，平台会保护您的隐私，不会泄露给第三方
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		CONFIG
	} from '@/config/app'
	import {
		getDoctorInfo,
		updateDoctorInfo
	} from '@/api/user'
	export default {
		data() {
			return {
				data: {},
				Url: CONFIG.HTTP_REQUEST_URL + 'app-api/infra/file/upload',
			}
		},
		onShow() {
			this.getDoctorInfo()
		},
		methods: {
			getDoctorInfo() {
				getDoctorInfo(this.request).then(res => {
					this.data = res.data
				})
			},
			image() {
				// this.$refs['authpup'].open()
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.showLoading({
							title: "上传中"
						});
						for (var i = 0; i < tempFilePaths.length; i++) {
							uni.uploadFile({
								url: this.Url,
								header: {
									'token': uni.getStorageSync('token'),
								},
								filePath: tempFilePaths[i],
								name: 'file',
								success: (uploadFileRes) => {
									uni.hideLoading();
									let data = ''
									if (JSON.parse(uploadFileRes.data).code == 0) {
										// updateBlindMemberUser({
										// 	avatar: JSON.parse(uploadFileRes.data).data,
										// 	auditAvatar: JSON.parse(uploadFileRes.data).data
										// }).then(res => {
										// 	uni.switchTab({
										// 		url: '/pages/index/index'
										// 	});
										// })
										this.data.avatar = JSON.parse(uploadFileRes.data).data
										updateDoctorInfo(this.data).then(res => {
											uni.showToast({
												title: '发布成功',
												icon: 'none',
												duration: 2000,
												mask: true
											})
											this.getDoctorInfo()
											// setTimeout(() => {
											// 	//需要定时执行的代码
											// 	uni.switchTab({
											// 		url: '/pages/index/index',
											// 	})
											// }, 2000)
										})
									} else {
										uni.showToast({
											title: JSON.parse(uploadFileRes.data).msg,
											icon: "none",
											duration: 2000
										});
									}
								},
								fail: () => {
									uni.hideLoading();
									uni.showToast("上传失败，请联系开发！")
								},
								complete: function() {
									uni.hideLoading();
								}
							});
						}
					}
				});
			},
			goinfo(e, id) {
				if (id) {
					uni.navigateTo({
						url: `/${e}?id=${id}`,
					})
				} else {
					uni.navigateTo({
						url: `/${e}`,
					})
				}
			},
		}
	}
</script>

<style lang="less" scoped>
	.container {
		padding-bottom: 100rpx;
	}

	.info {
		padding: 30rpx;

		.imgBox {
			.explain {
				font-weight: 500;
				font-size: 22rpx;
				color: rgba(153, 153, 153, 0.8);
			}

			.imgList {
				display: flex;
				justify-content: space-between;

				image {
					width: 311rpx;
					height: 187rpx;
					border-radius: 15rpx;
					margin-bottom: 20rpx;
				}
			}

			.imgTitle {
				display: flex;
				align-items: center;
				font-weight: 500;
				font-size: 28rpx;
				color: #333333;

				image {
					width: 27rpx;
					height: 27rpx;
					margin-left: 19rpx;

				}

				text {
					margin-right: 16rpx;
					display: inline-block;
					width: 10rpx;
					height: 10rpx;
					background: #333333;
					border-radius: 50%;
				}
			}
		}

		.textareaBox {
			font-weight: 500;
			font-size: 26rpx;
			color: #999999;
		}

		.name_info {
			font-weight: 500;
			font-size: 28rpx;
			color: #333333;

			text {
				color: #999999;
				display: inline-block;
				width: 160rpx;
				margin-bottom: 20rpx;
			}
		}

		.txBox {
			display: flex;
			align-items: center;

			image {
				width: 92rpx;
				height: 92rpx;
				border-radius: 50%;
				margin-right: 9rpx;
			}
		}

		.updata {
			image {
				width: 23rpx;
				height: 23rpx;
				margin-right: 9rpx;
			}

			font-size: 24rpx;
			color: #3E6EFE;
		}
	}
</style>